package com.mck.mapper;

import com.mck.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    /**
     * 查询所有用户
     */
    // 方法一
    // @Results({
    //         @Result(column = "user_id", property = "userId"),
    //         @Result(column = "user_type", property = "userType"),
    //         @Result(column = "create_time", property = "createTime"),
    //         @Result(column = "revise_time", property = "reviseTime")
    // })
    // @Select("select *  from user order by user_id")
    // List<User> findAll();

    // 方法二
    // @Select("select user_id userId, account, password, avatar, user_type userType, create_time createTime, revise_time reviseTime  from user order by user_id")
    // List<User> findAll();

    // 方法三
    // 在application.yml文件 开启驼峰命名，符合命名规范，mybatis会自动映射，不需要再定义别名
    // @Select("select *  from users order by user_id")
    List<User> findAllUser();

    /**
     * 根据用户数据获取对应用户数据
     */
    List<User> findUserInfoByUserInfo(User user);

    /**
     * 根据id删除用户
     */
    @Delete("delete from users where user_id = #{userId}")
    void deleteUserById(Integer userId);

    /**
     * 删除用户列表
     */
    @Delete("delete from users where user_id in (#{userId})")
    void deleteUserList(User user);

    /**
     * 添加用户
     */
    // @Insert("insert into users(account, password, uname, avatar_id, user_type_id, type_number, phone_number, create_time) values(#{account}, #{password},#{uname}, #{avatarId}, #{userTypeId}, #{typeNumber}, #{phoneNumber}, #{createTime})")
    void addUser(User user);


    /**
     * 添加用户列表
     */
    // @Insert("insert into users(account, password, uname, avatar_id, user_type_id, type_number, phone_number, create_time) values(#{account}, #{password},#{uname}, #{avatarId}, #{userTypeId}, #{typeNumber}, #{phoneNumber}, #{createTime})")
    @Options(useGeneratedKeys = true, keyProperty = "userId")
    void insertUserList(List<User> user);


    /**
     * 更新用户数据
     */
    void updateUser(User user);

    /**
     * 更新用户头像
     */
    void updateUserAvatar(User user);

}
